#include <cmath>
#include "MatProjection.hpp"


MatProjection::MatProjection(void)
{
}

MatProjection::MatProjection(const float angle, const float ratio, const float near, const float far)
{
	loadIdentity();
	perspective(angle, ratio, near, far);
}

MatProjection::~MatProjection(void)
{
}

void	MatProjection::perspective(const float angle, const float ratio, const float near, const float far)
{
	float	f = 1.0 / tan((angle / 2.0) * M_PI / 180.0);
	Mat4f	perspective;

	perspective.init();
	perspective(0, 0) = f / ratio;
	perspective(1, 1) = f;
	perspective(2, 2)= (near + far) / (near - far);
	perspective(2, 3) = (2 * near * far) / (near - far);
	perspective(3, 2) = -1;
	*this *= perspective;
}
